home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ9310.ZIP / 1993-OCT.ZIP / LIANA.ASC < prev    next >
Text File  |  1993-09-17  |  8KB  |  260 lines

  1. _THE LIANA PROGRAMMING LANGUAGE_
  2. by Ray Valdes
  3.  
  4. [LISTING ONE] 
  5.  
  6. //----- Liana program that uses Windows controls in a dialog. ------
  7. main
  8. {       window ();
  9.         w.menu = new menu
  10.             << new menuitem ("&Language Info...");
  11.         cr = "\n";
  12.         d = new language_info_dialog;
  13.         d.lang_name = "Liana";
  14.         d.language_type = "object-oriented";
  15.         d.provides_app_framework = true;
  16.         d.has_ide = false;
  17. }
  18. language_info { if (d.show) w.refresh; }
  19. paint
  20. {       w.home;
  21.         if (d)
  22.             w <<   "  Language name: " + d.lang_name + cr 
  23.               + "  Language type: " + d.language_type + cr
  24.               + "  Provides app framework: " + d.provides_app_framework + cr
  25.               + "  Has IDE: " + d.has_ide;
  26. }
  27. class language_info_dialog: dialog 
  28. {
  29.    public:
  30.           string lang_name,
  31.                  language_type;
  32.           bool   provides_app_framework, 
  33.                  has_ide;
  34.    language_info_dialog
  35.    {    
  36.           dialog ();
  37.           this << new labeltext ("Language name:")
  38.                << new edittext  (20, "lang_name");
  39.           this [0].under;  
  40.           south ();
  41.           this << new groupbox    ("Language Type")
  42.                << new radiobutton ("&Procedural")
  43.                << new radiobutton ("&Functional")
  44.                << new radiobutton ("&Object-oriented")
  45.                << new endgroupbox;
  46.  
  47.           this [2].after;
  48.           this << new checkbox ("Provides app framework")
  49.                << new checkbox ("Has IDE");
  50.           this [6].under;  
  51.           east();
  52.           this << new ok_button 
  53.                << new cancel_button;
  54.          }
  55. };
  56.  
  57.  
  58. [LISTING TWO]
  59.  
  60. //**** Linked list program that uses put_to ("<<") operator to append elements.
  61. // by Jack Krupansky, 1993.
  62. class  MyListData 
  63. {
  64.             Print { cout << "Object of class "+this.class_name; }
  65. };
  66. struct  MyListElement 
  67. {           MyListData    data;
  68.             MyListElement next;
  69.  
  70.             MyListElement (MyListData initialData)
  71.             {
  72.                     data = initialData; 
  73.             }
  74. };
  75. class  MyList : MyListData 
  76. {          MyListElement head;
  77.            MyListElement tail;
  78. public:
  79.             put_to (MyListData data)
  80.             {
  81.                 MyListElement newElement = new MyListElement (data);
  82.                 if (head)  tail.next = newElement; // Append to non-empty list
  83.                 else       head = newElement;      // Start from an empty list
  84.                 tail = newElement;            // Point to the new end of list
  85.                 return this;
  86.             }
  87.             Print
  88.             {
  89.                 for (int i = 0, MyListElement e = head; e; e = e.next)
  90.                             e.data.Print();
  91.             }
  92. };
  93. class  MyNumber : MyListData 
  94. {           int value;
  95.             MyNumber (int initialValue) { value = initialValue; }
  96.             Print { cout << "    Number: " + value + "\n";}
  97. };
  98. {           int x, y;
  99.             MyPoint (int initialX,int initialY)
  100.                     { x = initialX; y = initialY; }
  101.             Print { cout << "    Point: " + x + "," + y + "\n"; }
  102. };
  103. void main (void)
  104. {       MyList   list1 =   new  MyList;
  105.         MyList   list2 =   new  MyList;
  106.         MyNumber n1    =   new  MyNumber (10);
  107.         MyNumber n2    =   new  MyNumber (20);
  108.         MyPoint  p1    =   new  MyPoint  (2,3);
  109.         MyPoint  p2    =   new  MyPoint  (4,5);
  110.         /* build the lists */
  111.         list1 << n1 << n2 << p1;
  112.         /* an object can be in more than one list at same time */
  113.         list2 << n2 << p1 << p2;
  114.         list2 << list1; // we can even put a list into another list 
  115.         /* print the lists */
  116.         cout << "\nLIST1:\n";    list1.Print;    
  117.         cout << "\nLIST2:\n";    list2.Print;
  118. }
  119.  
  120.  
  121. [LISTING THREE]
  122.  
  123. //*** Linked list program that subclasses "Linkable", by Ray Valdes, 1993. ***
  124. class Linkable {
  125.         Linkable next;
  126.         Linkable GetNext    { return next; }
  127.         SetNext(Linkable n) { next = n; }    
  128.         Print { w << "Should override this method.\n"; }
  129. };
  130. class MyPoint : Linkable {
  131.         int x,y;
  132.         MyPoint(int xx,int yy) { x = xx; y = yy; }
  133.         Print { w << "Point ("+ x + "," + y  + ")\n"; }
  134. };
  135. class MyNumber : Linkable {
  136.         int value;
  137.         MyNumber(int v) { value = v; }
  138.         Print { w << "Integer " + value  + "\n"; }
  139. };
  140. class MyList : Linkable {
  141.         Linkable head,tail;
  142.         int count;
  143.         AddToList(Linkable item) {  
  144.            count++;
  145.            if(! head)  { head = tail = item; }
  146.            else        { tail.SetNext(item); tail = item; }
  147.         }
  148.         Print {
  149.            for(int i = 0, Linkable x = head; i < count; i++, x = x.GetNext) 
  150.                     x.Print;
  151.         }
  152. };
  153. main {  (w = new window).show;  w << "Sample List Program in LIANA\n"; 
  154.         MyList  list1 =   new   MyList;
  155.         MyList  list2 =   new   MyList; 
  156.         MyNumber n1   =   new   MyNumber  (10);
  157.         MyNumber n2   =   new   MyNumber  (20);
  158.         MyPoint  p1   =   new   MyPoint   (2,3);
  159.  
  160.         // build the lists 
  161.         list1.AddToList (n1);
  162.         list1.AddToList (n2);
  163.  
  164.         // an object can be in more than one list at same time
  165.         list2.AddToList (n2);
  166.         list2.AddToList (p1);
  167.  
  168.         // a list can contain another list as an element
  169.  
  170.         // print the lists (should also print the content of any sublists)
  171.         w << "LIST1:\n";    list1.Print;
  172.         w << "LIST2:\n";    list2.Print;
  173.         w << "Done.\n";
  174. }
  175.  
  176.  
  177. Example 1: 
  178.  
  179.  
  180. startdrag (x1, y1, x2, y2) 
  181. {
  182.     w.line (old_x1 = x1, old_y1 = y1, old_x2 = x2, old_y2 = y2);
  183. }
  184. drag (x, y) 
  185. {
  186.     w.xor = true;
  187.     w.line (old_x1, old_y1, old_x2,     old_y2    );   // Erase prev line
  188.     w.line (old_x1, old_y1, old_x2 = x, old_y2 = y);   // Draw  new  line
  189.     w.xor = false;
  190. }
  191.  
  192.  
  193. Example 2: 
  194.  
  195. startdrag (x1, y1, x2, y2) 
  196. {
  197.     w.line (old_x1 = x1, old_y1 = y1, old_x2 = x2, old_y2 = y2);
  198.  
  199. }
  200. drag (x, y) 
  201. {
  202.     w.xor = true;
  203.     w.line (old_x1, old_y1, old_x2, old_y2);          // Erase prev line
  204.     w.line (old_x1, old_y1, old_x2 = x, old_y2 = y);  // Draw  new  line
  205.     w.xor = false;
  206. }
  207. enddrag (x, y) 
  208. {
  209.     if (! lines) lines = new array;
  210.     lines << new line (old_x1, old_y1, old_x2, old_y2);
  211. }
  212. paint 
  213. {
  214.     for (int i = 0; lines && i < lines.size; i++) 
  215.               lines [i].draw (w);
  216. }
  217.  
  218.  
  219. Example 3: 
  220.  
  221. main { window();  w.status_line_enabled = true; }
  222. position (x,y)  { w.status = x+","+y+"       "; }
  223.  
  224.  
  225.  
  226. Example 4: 
  227.  
  228. class  MyList : array
  229. {
  230.      Print
  231.      {
  232.           for (int i = 0, int n = size; i < n; i++)
  233.                 if ((any e = this [i]).isa ("MyList"))
  234.                   e.Print();
  235.                 else
  236.                   cout << e.class_name+": "+e.text+"\n";
  237.      }
  238. };
  239. //-------------------------------------------
  240. void main (void)
  241. {
  242.         MyList  list1 =   new   MyList;
  243.         MyList  list2 =   new   MyList;
  244.         int     n1 =      10;
  245.         int     n2 =      20;
  246.         point   p1 =      new   point (2,3);
  247.         point   p2 =      new   point (4,5);
  248.         /* build the lists */
  249.         list1 << n1 << n2 << p1;
  250.         /* an obj can be in more than one lst at same time */
  251.         list2 << n2 << p1 << p2;
  252.         list2 << list1; /* we can even put a list into another list  */
  253.         /* print the lists */
  254.         cout << "\nLIST1:\n";    list1.Print;
  255.         cout << "\nLIST2:\n";    list2.Print;
  256. }
  257.  
  258.  
  259.  
  260.